/**
 * MIT License
 *
 * Copyright (C) 2023 Huawei Device Co., Ltd.
 *
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the "Software"), to deal
 * in the Software without restriction, including without limitation the rights
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in all
 * copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
 * SOFTWARE.
 */

#ifndef HEADER_FILE_CPP_P_OPS_H
#define HEADER_FILE_CPP_P_OPS_H

#include <jsi/jsi.h>
#include <react/renderer/components/view/ViewProps.h>
#include <react/renderer/core/PropsParserContext.h>
#include <react/renderer/graphics/Color.h>

namespace facebook {
namespace react {

enum class RNDateTimePickerMode { DATE, TIME, DATETIME, COUNTDOWN};

inline void fromRawValue(const PropsParserContext& context,
    const RawValue &value, RNDateTimePickerMode &result)
{
    auto string = (std::string)value;
    if (string == "date") {
        result = RNDateTimePickerMode::DATE;
        return;
    }
    if (string == "time") {
        result = RNDateTimePickerMode::TIME;
        return;
    }
    if (string == "datetime") {
        result = RNDateTimePickerMode::DATETIME;
        return;
    }
    if (string == "countdown") {
        result = RNDateTimePickerMode::COUNTDOWN;
        return;
    }
    throw std::runtime_error("Invalid display type")
}

inline std::string toString(const RNDateTimePickerMode &value)
{
    switch (value) {
        case RNDateTimePickerMode::DATE: return "date";
        case RNDateTimePickerMode::TIME: return "time";
        case RNDateTimePickerMode::DATETIME: return "datetime";
        case RNDateTimePickerMode::COUNTDOWN: return "countdown";
    }
}

enum class RNDateTimePickerThemeVariant { DARK, LIGHT, UNSPECIFIED};

inline void fromRawValue(const PropsParserContext& context,
    const RawValue &value, RNDateTimePickerThemeVariant &result)
{
    auto string = (std::string)value;
    if (string == "dark") {
        result = RNDateTimePickerThemeVariant::DARK;
        return;
    }
    if (string == "light") {
        result = RNDateTimePickerThemeVariant::Light;
        return;
    }
    if (string == "unspecified") {
        result = RNDateTimePickerThemeVariant::UNSPECIFIED;
        return;
    }
    throw std::runtime_error("Invalid display type")
}

inline std::string toString(const RNDateTimePickerThemeVariant &value)
{
    switch (value) {
        case RNDateTimePickerThemeVariant::DARK: return "dark";
        case RNDateTimePickerThemeVariant::LIGHT: return "light";
        case RNDateTimePickerThemeVariant::UNSPECIFIED: return "unspecified";
    }
}
enum class RNDateTimePickerDisplayIOS { DEFAULT, SPINNER, COMPACT, INLINE};

inline void fromRawValue(const PropsParserContext& context,
    const RawValue &value, RNDateTimePickerDisplayIOS &result)
{
    auto string = (std::string)value;
    if (string == "default") {
        result = RNDateTimePickerDisplayIOS::DEFAULT;
        return;
    }
    if (string == "spinner") {
        result = RNDateTimePickerDisplayIOS::SPINNER;
        return;
    }
    if (string == "compact") {
        result = RNDateTimePickerDisplayIOS::COMPACT;
        return;
    }
    if (string == "inline") {
        result = RNDateTimePickerDisplayIOS::INLINE;
        return;
    }
    throw std::runtime_error("Invalid display type")
}

inline std::string toString(const RNDateTimePickerDisplayIOS &value)
{
    switch (value) {
        case RNDateTimePickerDisplayIOS::DEFAULT: return "default";
        case RNDateTimePickerDisplayIOS::SPINNER: return "spinner";
        case RNDateTimePickerDisplayIOS::COMPACT: return "compact";
        case RNDateTimePickerDisplayIOS::INLINE: return "inline";
    }
}

class JSI_EXPORT RNDateTimePickerProps final : public ViewProps {
    public:
        RNDateTimePickerProps() = default;
        RNDateTimePickerProps(const PropsParserContext& context,
            const RNDateTimePickerProps &sourceProps,
            const RawProps &rawProps);
#pragma mark - Props
    int64_t maximumDate{0};
    int64_t minimumDate{0};
    int64_t date{0};
    std::string locale{};
    int minuteInterval{0};
    std::string mode{ toString(RNDateTimePickerMode::Date)};
    facebook::react::Float timeZoneOffsetInMinutes{0.0};
    std::string timeZoneName{};
    std::string textColor{};
    std::string accentColor{};
    std::string themeVariant{toString(RNDateTimePickerThemeVariant::Unspecified)};
    std::string displayIOS{toString(RNDateTimePickerDisplayIOS::Default)};
    bool enabled{true};
    bool is24Hour{true};
};
}
}
#endif